<?php
/**
 * PageView class
 * Generates XHTML page
 * functions to get XHTML, add meta tags and render tags into html
 */

class PageView {
	//Private variables to store metaTags and charset
  	private $m_metaTags = array();
  	private $m_charset;
	
	//Constructor, takes charset as parametar, if none given use UTF-8
	public function __construct($charset = "utf-8"){
		//set the charset var
		$this->m_charset = $charset;
	}
	
	//Public funtion to add stylesheets
	public function AddStyleSheet($href){
		//Store the link in ou rarray
		$this->m_metaTags[] = "<link rel='StyleSheet' href='$href' type='text/css'";
	}
	
  /**
   * Builds meta and CSS tags as a HTML/XML string
   *    
   * @param bool $isXML is the document an XML file and tags should be closed 
   * @return string  
   */
 	private function BuildHeadTags($isXML) {
    		
		//Declare end-tag
    	if ($isXML) {
      		$end = "/>";
    	}
		else {
			$end = ">";
		}
		//Declare var to hold our headtags
    	$retValue = "";
		
		//Fill it with the tags in our array
    	foreach($this->m_metaTags as $tag) {
      		$retValue .= $tag . "$end\n            "; // "\n            " for readability
    	}
		
		//Return it
    	return $retValue;
  	}
	
	/**
	  * Returns a XHTML page
	  * @param string $title  
	  * @param string $body    
	  * @return string     
	  **/
	public function GetXHTML10StrictPage($title, $body) {
		$head = $this->BuildHeadTags(true);
		$xml = "
	        <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> 
	        <html xmlns=\"http://www.w3.org/1999/xhtml\"> 
	          <head> 
	             <title>$title</title> 
	             <meta http-equiv=\"content-type\" content=\"text/html; charset=$this->m_charset\" /> 
	             $head
	          </head> 
	          <body>
	            $body
	          </body>
	        </html>";
		return $xml;
	}
			
	/**
	 * TEST AREA
	 * @bolean Testresult
	 * Return true or false and echos errorstring
	 */
	public function Test(){
		
		
	}
}
